﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using IdeaNMR.Shared.Utils;

namespace IdeaNMR.Web.Core
{
    public partial class BaseObject : ICopyable
    {
        #region ICopyable Members
        public virtual void CopyTo(object target, bool IncludeUniqueFields)
        {
            if (target == null)
                throw new ArgumentNullException();

            if (!(target is BaseObject))
                throw new ArgumentException("BaseObject.CopyTo; target is not BaseObject.");

            BaseObject o = (BaseObject)target;

            if (IncludeUniqueFields)
            {
                o.Id = this.Id;
                o.Datetime = this.Datetime;
            }

            o.Name = this.Name;
            o.Info = this.Info;
            o.VersionInfo = this.VersionInfo;
            o.Script = this.Script;
            o.IsDraft = this.IsDraft;
            o.IsPrivate = this.IsPrivate;
        }

        #endregion
    }

    public partial class HardObject : ICopyable
    {
        #region ICopyable Members
        /// <summary>
        /// 
        /// </summary>
        /// <param name="target"></param>
        /// <exception cref="System.ArgumentNullException">When <paramref name="target"/> is null.</exception>
        public override void CopyTo(object target, bool IncludeUniqueFields)
        {
            if (target == null)
                throw new ArgumentNullException();
            if (!(target is HardObject))
                throw new ArgumentException("HardObject.CopyTo; target is not HardObject.");

            HardObject o = (HardObject)target;

            base.CopyTo(o, IncludeUniqueFields);
            o.ContactEmail = this.ContactEmail;
            o.ContactPerson = this.ContactPerson;
            o.Location = this.Location;
        }

        #endregion
    }

    public partial class NMRObject : ICopyable
    {
        #region ICopyable Members
        public override void CopyTo(object target, bool IncludeUniqueFields)
        {
            if (target == null)
                throw new ArgumentNullException();
            if (!(target is NMRObject))
                throw new ArgumentException("NMRObject.CopyTo; target is not NMRObject.");

            NMRObject o = (NMRObject)target;

            base.CopyTo(o, IncludeUniqueFields);

            o.Content = this.Content;
        }

        #endregion
    }

    public partial class PulseProgram : ICopyable
    {
        #region ICopyable Members
        public override void CopyTo(object target, bool IncludeUniqueFields)
        {
            if (target == null)
                throw new ArgumentNullException();
            if (!(target is PulseProgram))
                throw new ArgumentException("PulseProgram.CopyTo; target is not PulseProgram.");

            PulseProgram o = (PulseProgram)target;

            base.CopyTo( target, IncludeUniqueFields);

            o.Type = this.Type;
            o.Dimensionality = this.Dimensionality;
            o.Analytics = this.Analytics;


            o.SpinachMacro = this.SpinachMacro;

        }
        #endregion
    }

    public partial class Wave : ICopyable
    {
        public override void CopyTo(object target, bool IncludeUniqueFields)
        {
            if (target == null) target = new Wave();
            else if (!(target is Wave))
                throw new ArgumentException("Wave.CopyTo; target is not Wave.");


            base.CopyTo(target, IncludeUniqueFields);
        }
    }

    public partial class Script : ICopyable
    {
        #region ICopyable Members
        public override void CopyTo(object target, bool IncludeUniqueFields)
        {
            if (target == null)
                throw new ArgumentNullException();
            if (!(target is Script))
                throw new ArgumentException("Script.CopyTo; target is not Script.");

            Script o = (Script)target;

            base.CopyTo(target, IncludeUniqueFields);

            o.Type = this.Type;
            o.IsIncludable = this.IsIncludable;
        }
        #endregion
    }

    public partial class Sample : ICopyable
    {
        #region ICopyable Members
        public override void CopyTo(object target, bool IncludeUniqueFields)
        {
            if (target == null)
                throw new ArgumentNullException("Sample.CopyTo; target is null.");
            if (!(target is Sample))
                throw new ArgumentException("Sample.CopyTo; target is not of type Sample.");

            Sample o = target as Sample;

            base.CopyTo(o, IncludeUniqueFields);
            o.Buffer = this.Buffer;
            o.Labeling = this.Labeling;
        }

        #endregion
    }

    public partial class Spectrometer : ICopyable
    {
        #region ICopyable Members
        public override void CopyTo(object target, bool IncludeUniqueFields)
        {
            if (target == null)
                throw new ArgumentNullException("Spectrometer.CopyTo; target is null.");
            if (!(target is Spectrometer))
                throw new ArgumentException("Spectrometer.CopyTo; target is not of type Spectrometer.");

            Spectrometer o = target as Spectrometer;

            base.CopyTo(o, IncludeUniqueFields);
            o.Frequency = this.Frequency;
        }

        #endregion
    }

    public partial class User : ICopyable
    {
        #region ICopyable Members

        public void CopyTo(object target, bool IncludeUniqueFields)
        {
            if (target == null)
                throw new ArgumentNullException("User.CopyTo. Target is null.");
            if (!(target is User))
                throw new ArgumentException("User.CopyTo. target must be of type user or derived from it.");

            User o = target as User;

            if (IncludeUniqueFields)
                o.Username = this.Username;

            o.Firstname = this.Firstname;
            o.Middlename = this.Middlename;
            o.Lastname = this.Lastname;
            o.Datetime = this.Datetime;
        }

        #endregion
    }
}
